
from utils import Json,util

from apps.user_operation.serializers import appTabSerializers,appSerializers
from apps.user_operation.models import AppTabSetting,AppSetting

from rest_framework.views import  APIView
from django.views.decorators.csrf import csrf_exempt
from Blog import settings

class user_operationApi(APIView):

    """
    获取app信息
    """
    @csrf_exempt
    def appGlobalInfo(request):

        #app设置
        app = AppSetting.objects.first()
        if app:
            appSer = appSerializers(app)
            app_dict = appSer.data
            app_dict["launchImage"] = util.add_PhotoWithurl(app_dict["launchImage"])

            # 主题
            tabItems = AppTabSetting.objects.all()
            tab_list = []

            for tabItem in tabItems:
                tabItemSer = appTabSerializers(tabItem)
                re_dict = tabItemSer.data
                re_dict["norbgImage"] = util.add_PhotoWithurl(re_dict["norbgImage"])
                re_dict["selectbgImage"] = util.add_PhotoWithurl(re_dict["selectbgImage"])
                tab_list.append(re_dict)

            return Json.json_response({"app":app_dict,"tab_list":tab_list})
        else:
            return Json.json_response({})